package dev.sharp.ymcloud.cloud;

import android.content.Context;

import com.stardust.autojs.execution.ScriptExecution;
import com.stardust.autojs.script.ScriptSource;


import java.io.File;

import dev.sharp.ymcloud.Pref;
import dev.sharp.ymcloud.autojs.AutoJs;
import dev.sharp.ymcloud.model.script.ScriptFile;
import dev.sharp.ymcloud.model.script.Scripts;
import dev.sharp.ymcloud.network.API;
import dev.sharp.ymcloud.network.http.HttpClient;

public class ScriptsHelper {
    /*
     *
     * */
    public static void run(ScriptFile scriptFile) {
        ScriptExecution ex = Scripts.run(scriptFile);
    }

    /**
     * 停止所有在运行的脚本
     */
    public static int stopAll() {
        return AutoJs.getInstance().getScriptEngineService().stopAll();
    }

    public static ScriptFile LoadScript(Context context, int scriptid, int deviceid) throws Exception {
        HttpClient client = new HttpClient();
        File folder = context.getCacheDir();
        File file = client.loadFile(API.getUrl("/Script/GetScriptWhithArgs?scriptid=" + scriptid + "&deviceid=" + deviceid), folder, null, null);
        return new ScriptFile(file);
    }

}
